<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>

<body>
    <div id='app'>
        我是app组件===={{msg}}====={{msg2}}
        <father :app='msg' @toapp='show'></father>
    </div>
    <script type='text/javascript'>
        var son = {
            props: ['fa'],
            template: `<div class='son'>
                我是son==={{fa}}
                <button @click="ss">son向父组件father传值</button>
            </div>`,
            data() {
                return {
                    s1: '这是son组件中的数据'
                }
            },
            methods: {
                ss() {
                    this.$emit('tofather', this.s1)
                }
            }
        }
        var father = {
            props: ['app'],
            template: `<div class='father'>
                我是father====={{f1}}=={{app}}===={{f2}}
                <button @click="ff">father向父组件app传值</button>
                <hr/>
                <son :fa='f1' @tofather="fshow"></son>
            </div>`,
            data() {
                return {
                    f1: '这是father组件中的数据',
                    f2:''
                }
            },
            components: {
                son: son
            },
            methods: {
                ff() {
                    this.$emit('toapp', this.f1)
                },
                fshow(message) {
                    console.log(message, 222);
                    this.f2=message
                }
            }
        }

        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello APP',
                msg2: ''
            },
            components: {
                father: father   //挂载
            },
            methods: {
                show(message) {
                    console.log(message, 1111);
                    this.msg2 = message

                }
            }
        });
    </script>
</body>

</html>